package com.UI
{
	import com.*;
	import com.Engine.*;
	import com.Packet.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.external.*;
	import flash.filters.*;
	import flash.geom.*;
	import flash.system.*;
	import flash.text.*;
	import flash.ui.*;
	import flash.utils.*;
	
	import gs.*;
	import gs.easing.*;
	import gs.events.TweenEvent;
	
	import org.aswing.*;
	import org.aswing.border.*;
	import org.aswing.border.EmptyBorder;
	import org.aswing.colorchooser.*;
	import org.aswing.dnd.*;
	import org.aswing.event.*;
	import org.aswing.ext.*;
	import org.aswing.geom.*;
	import org.aswing.tree.AbstractLayoutCache;
	
	public class FrameChatRecord extends JFrame
	{
		//members define
		private var panel24:JPanel;
		private var btn_tab_chat:JToggleButton;
		private var panel26:JPanel;
		private var textChat:JTextArea;
		
		//-----------------------------------
		private var btn_close:JButton;
		public function FrameChatRecord()
		{
			super();
			//setClosable(false);
			setResizable(false);  
			setBorder(new EmptyBorder());
			btn_close = new JButton();
			btn_close.setLocation(new IntPoint(448, 0));
			btn_close.setSize(new IntDimension(35, 34));
			btn_close.setPreferredSize(new IntDimension(35, 34));
			this.getTitleBar().setCloseButton(btn_close);
			
			//component creation
			setSize(new IntDimension(499, 351));
			setPreferredSize(new IntDimension(499, 351));
			var layout0:SoftBoxLayout = new SoftBoxLayout();
			layout0.setAxis(AsWingConstants.VERTICAL);
			layout0.setAlign(AsWingConstants.LEFT);
			layout0.setGap(0);
			getContentPane().setLayout(layout0);
			
			panel24 = new JPanel();
			panel24.setLocation(new IntPoint(10, 5));
			panel24.setSize(new IntDimension(499, 31));
			panel24.setPreferredSize(new IntDimension(499, 31));
			var layout1:FlowLayout = new FlowLayout();
			layout1.setAlignment(AsWingConstants.LEFT);
			layout1.setHgap(25);
			layout1.setVgap(0);
			panel24.setLayout(layout1);
			
			btn_tab_chat = new JToggleButton();
			btn_tab_chat.setLocation(new IntPoint(5, 5));
			btn_tab_chat.setSize(new IntDimension(60, 29));
			btn_tab_chat.setPreferredSize(new IntDimension(60, 29));
			btn_tab_chat.setText("label");
			
			panel26 = new JPanel();
			panel26.setLocation(new IntPoint(0, 31));
			panel26.setSize(new IntDimension(494, 280));
			panel26.setPreferredSize(new IntDimension(499, 280));
			var layout2:CenterLayout = new CenterLayout();
			panel26.setLayout(layout2);
			
			textChat = new JTextArea();
			textChat.setLocation(new IntPoint(5, 5));
			textChat.setSize(new IntDimension(464, 268));
			textChat.setPreferredSize(new IntDimension(464, 268));
			
			//component layoution
			getContentPane().append(panel24);
			getContentPane().append(panel26);
			
			panel24.append(btn_tab_chat);
			
			panel26.append(textChat);
			//--------------------
			textChat.addEventListener(TextEvent.LINK, linkHandlerChat);
			setImages();
		}
		private function linkHandlerChat(linkEvent:TextEvent):void 
		{
			//var charId:int = int(linkEvent.text);
			//Client.getInstance().sendPacketLogic(1302,[charId]);
			FrameClickChar.show(_frame,0,0);
		}
		public function setImages():void
		{
			btn_close.wrapSimpleButton(Client.getUIElement("btn_close") as SimpleButton);
			var img_background:DisplayObject = Client.getUIElement("img_chat_popup_background") as DisplayObject
			setBackgroundDecorator(new AssetBackground(img_background));
			//setSizeWH(img_background.width,img_background.height);
			setSize(new IntDimension(img_background.width, img_background.height));
			setPreferredSize(new IntDimension(img_background.width, img_background.height));
			setLocationXY((Engine.W - width) / 2,(Engine.H - height)/2);
			
			btn_tab_chat.setSelected(true);
			btn_tab_chat.wrapSimpleButton(Client.getUIElement("btn_tab_chat") as SimpleButton);
			btn_tab_chat.setText("");
			var group:ButtonGroup = new ButtonGroup();
			group.appendAll(btn_tab_chat);
			

			textChat.setEditable(false);
			textChat.setWordWrap(true);
			
			textChat.setBackgroundDecorator(null);
			
			var filter:GlowFilter;
			var font:ASFont = new ASFont("宋体", 12, false, false, false, false);
			filter = new GlowFilter(0xFFFFFF, 1, 2, 2, 50);
			textChat.setFont(font);
			textChat.filters = new Array(filter);
			textChat.setForeground(new ASColor(ASColor.WHITE.getARGB()));
			
			textChat.setHtmlText(FrameChat.getInstance().textMessage);
			textChat.scrollToBottomLeft();
		}
		
		private static var _frame:FrameChatRecord = null;
		public static function show():void
		{
			if(isShowing())
			{
				hide()
				return;
			}
			if(_frame == null)
			{
				_frame = new FrameChatRecord();
				PanelMainHelp.getInstance().addChild(_frame);
			}
			_frame.show();
			PanelMainHelp.getInstance().bringToTop(_frame);
			Client.getInstance().sendPacketLogic(12,[1,0]);
			Client.getInstance().sendPacketLogic(12,[2,0]);
			
			_frame.x = (Engine.W - _frame.width) / 2;
			_frame.y = (Engine.H - _frame.height) / 2;
			
			_frame.alpha = 0.1;
			TweenLite.to(_frame, 0.5, {autoAlpha:1.0});
			update();
			
		}
		public static function hide():void
		{
			if(isShowing())_frame.hide();
		}
		public static function isShowing():Boolean
		{
			return(_frame != null&& _frame.isShowing());
		}
		public static function update():void
		{
			if(!isShowing())
				return;
			_frame.textChat.setHtmlText(FrameChat.getInstance().textMessage);
			_frame.textChat.scrollToBottomLeft();
		}
	}
}